package com.start.boot.service.impl;


import com.start.boot.dao.ajpc.OriganizationMapper;
import com.start.boot.domain.Param_TransJob;
import com.start.boot.service.OriganizationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lenovo on 2017/10/25.
 */

@Service
@Transactional
public class OriganizationServiceImpl  implements OriganizationService {


    @Autowired
    private OriganizationMapper origanizationMapper;


    @Override
    public void getDwbm(Map map) {
        origanizationMapper.getDwbm(map);
    }

    @Override
    public void getDwBmJsInfoByDwBm(Map map) {
        origanizationMapper.getDwBmJsInfoByDwBm(map);
    }


    @Override
    public void AddBmInfo(Map map) {
        origanizationMapper.addBmInfo(map);
    }

    @Override
    public void GetBmInfo(Map map) {
        origanizationMapper.getBmInfo(map);
    }

    @Override
    public void DeleteBmInfo(Map map) {
        origanizationMapper.deleteBmInfo(map);
    }

    @Override
    public void AddJsInfo(Map map) {
        origanizationMapper.addJsInfo(map);
    }

    @Override
    public void GetJsxh(Map map) {
        origanizationMapper.getJsxh(map);
    }

    @Override
    public void DeleteJsInfo(Map map) {
        origanizationMapper.deleteJsInfo(map);
    }

    @Override
    public void AddJsgnfp(Map map) {
        origanizationMapper.addJsgnfp(map);
    }

    @Override
    public void GetJsGnqx(Map map) {
        origanizationMapper.getJsGnqx(map);
    }

    /**
     * 添加单位功能权限
     * @param dwbm
     * @param gnbmj
     */
    @Override
    public void AddDwGnQx(String dwbm, String gnbmj) throws Exception {
            if (StringUtils.isEmpty(dwbm) || StringUtils.isEmpty(gnbmj) ) {
                return ;
            }

            //移除单位权限：
             Map map = new HashMap();
            map.put("p_dwbm", dwbm);

             origanizationMapper.removeDwGnQx(map);

             //添加单位权限
            Map map2 = new HashMap();
            map2.put("p_dwbm", dwbm);

            String[] gnbms = gnbmj.split(",");
            List<String> list = new ArrayList();

             for (int i = 0; i < gnbms.length; i++) {
                    if (StringUtils.isNotEmpty(gnbms[i])){
                        map2.put("p_gnbm",gnbms[i]);
                        origanizationMapper.addDwGnQx(map2);
                    }
             }

    }

    /**
     * 获取人员列表
     * @param map
     */
    @Override
    public void GetRyInfo(Map map) {
        origanizationMapper.getRyInfo(map);
    }

    @Override
    public void GetWfpRyInfo(Map map) {
        origanizationMapper.getWfpRyInfo(map);
    }

    @Override
    public void GetAllGnqx(Map map) {
        origanizationMapper.getAllGN(map);
    }

    @Override
    public void AddRYJSFP(Map map) {
        origanizationMapper.addRYJSFP(map);
    }

    @Override
    public void removeJob(Param_TransJob param_transJob) throws Exception {

        //调岗.移除
        Map map = new HashMap();
        map.put("p_dwbm", param_transJob.getDWBM());
        map.put("p_bmbm", param_transJob.getBMBM_Old());
        map.put("p_jsbm", param_transJob.getJSBM_Old());
        map.put("p_gh", param_transJob.getRYGH());

        origanizationMapper.removeJob(map);

        //调岗.添加
        Map map2 = new HashMap();
        map2.put("p_dwbm", param_transJob.getDWBM());
        map2.put("p_bmbm", param_transJob.getBMBM());
        map2.put("p_jsbm", param_transJob.getJSBM());
        map2.put("p_gh", param_transJob.getRYGH());

        origanizationMapper.transJob(map);
    }

    @Override
    public void GetJSInfoByDwBm(Map map) {
        origanizationMapper.getJSInfoByDwBm(map);
    }

    @Override
    public void RemoveJob(Map map) throws Exception {
        origanizationMapper.removeJob(map);
    }

    @Override
    public void GetBMBM(Map map) {
        origanizationMapper.getBMBM(map);
    }
}
